import router from '../router.js'
import store from '../store.js'
import { getToken } from '@/utils/auth' // 验权


const whiteList = ['/login'] // 不重定向白名单

router.beforeEach((to, from, next) => {

    //判断是否有token
    if(getToken()) {
        let routers1 = JSON.parse(localStorage.getItem('resourcesrList'));
        //已登录且在登录页则跳转首页
        if(to.path === '/login') {
            if (routers1==[]||routers1.length==0){
                next({ path: '/home' })
            } else {
                next({ path: routers1[0].nodes[0].url })
            }

        } else {
                next()
        }
    } else {
        //判断当前路由是否在白名单内
        if (whiteList.indexOf(to.path) != -1) {
            next()
        } else {
            next('/login')
        }
    }
})
